package com.lq.ecoldchain.ui.withdraw.addcard

import android.arch.lifecycle.MutableLiveData
import com.lq.ecoldchain.base.viewmodel.BaseViewModel
import com.lq.ecoldchain.internet.BaseObserver
import com.lq.ecoldchain.util.MD5
import com.lq.ecoldchain.util.toast

/*
*2019/1/7 0007  17:23
*function by lq
*/
class AddCardViewModel:BaseViewModel(){
    val name by lazy { MutableLiveData<String>() }
    val bankName by lazy { MutableLiveData<String>() }
    val bankNo by lazy { MutableLiveData<String>() }
    val payPassword by lazy { MutableLiveData<String>() }
    val map by lazy { HashMap<String, String>() }

    fun commit() {
        if(name.value.isNullOrEmpty() || bankName.value.isNullOrEmpty()|| bankNo.value.isNullOrEmpty()||payPassword.value.isNullOrEmpty()){
            toast { "请填写好完整信息" }
        }else{
            map.clear()
            map["name"] = name.value!!
            map["bankName"] = bankName.value!!
            map["bankNo"] = bankNo.value!!
            map["payPassword"] = MD5.encode(payPassword.value!!)
            BaseNetCore.ApiServiceImpl.addCard(map).compose(RxTransformer.switchSchedulers()).subscribe(object: BaseObserver<String>(){
                override fun onSuccess(t: String?) {
                    toast { "添加成功" }
                }

                override fun onFail(code: String) {
                }
            })
        }
    }
}